home *** CD-ROM | disk | FTP | other *** search
- /*
- * COPYRIGHT 1987 CORNELL UNIVERSITY; All Rights Reserved
- * Please see detailed copyrights and disclaimers in "notice.h"
- */
- #include <notice.h>
-
- /* 8/14/87 kevin fixed Peter's new download code to work on the Mac */
-
- /***************************************************************************
- **** 3270 File Transfer ****
- **** written by Peter Hoyt, Cornell Computer Services ****
- ***************************************************************************/
-
- #include <em.h>
-
- #include <3270.h>
- #include <h19.h>
-
-
- unsigned char ft_table[] = {0x02,0x07,0x0d,0x11,0x13,0x7f,0xff};
- unsigned char ft_input_table[] = {0x02,0x11,0x13,0x7f,0xff};
-
- /* This routine assembles incoming bytes from c19. */
-
- #ifdef ANTIQUE
- /* ftc19 packet structure used for upload & download */
-
- struct ftc19_pkt {
- unsigned pkt_len; /* total number of bytes to be uploaded */
- unsigned len; /* length of downloaded data */
- unsigned chk; /* chksum of downloaded */
- char lbuff[4]; /* length characters xmitted */
- char cbuff[4]; /* chksum characters xmitted */
- char data[600]; /* xfer data buffer */
- } ftpkt, uppkt;
-
- #endif
-
- /* PAGE */
-
- cft(data) /* handles version number */
- char data;
- {
- emdp->cft_count = emdp->input_cnt = emdp->input_state = 0;
- emdp->event_reg |= TFTP_ON;
- (*emdp->putchar)((char) 0xfd);
- (*emdp->putchar)((char) ftinit ((int) data, emdp->ibm_mode ? FALSE : TRUE));
- (*emdp->putchar)((char) 0x0d);
- mode = vtmode = CFT2MODE;
- }
-
- cft2()
- {
- /* eat the next 70 characters */
- if (++emdp->cft_count == 70)
- mode = vtmode = C19FTMODE;
- }
-
- /* This routine deals with incomming file transfer data:
- * The incomming bytes are assembled into an ftc19 packet.
- * It is checked for length, then gets escape sequences resolved,
- * and then gets its chksum verified. Finally its 7 bit data is expanded
- * into 8 bits and the file transfer routine ft3270() is called.
- */
-
- c19ft(data)
- char data;
- {
- int i;
- switch (emdp->input_state) {
- case 0: /* assembling the length of packet */
- emdp->rcv_pkt.lbuff[emdp->input_cnt] = data;
- if (emdp->input_cnt == 3) {
- for (emdp->rcv_pkt.len = 0, i = 0; i < 4; ++i)
- emdp->rcv_pkt.len = (emdp->rcv_pkt.len << 4) + (emdp->rcv_pkt.lbuff[i] & 0x0f);
- emdp->input_state = 1;
- }
- emdp->input_cnt = ++emdp->input_cnt & 3; /* resets to 0 on way out */
- break;
- case 1: /* assembling the chksum */
- emdp->rcv_pkt.cbuff[emdp->input_cnt] = data;
- if (emdp->input_cnt == 3) {
- for (emdp->rcv_pkt.chk = 0, i = 0; i < 4; ++i)
- emdp->rcv_pkt.chk = (emdp->rcv_pkt.chk << 4) + (emdp->rcv_pkt.cbuff[i] & 0x0f);
- emdp->input_state = 2;
- }
- emdp->input_cnt = ++emdp->input_cnt & 3;
- break;
- case 2: /* gathering data */
- if (data != 0x7f)
- *(emdp->rcv_pkt.data+emdp->input_cnt++) = data;
- else {
- if (ft_process()) /* unravel headers & call ft3270() */
- ft_req(); /* rc != 0: request re-xmission */
- emdp->input_cnt = emdp->input_state = 0;
- }
- break;
- }
- }
-
-
- /* This routine processes an incoming block from telnet. */
-
- tnft(ptr, len)
- char *ptr;
- int len;
- {
- int i;
-
- if (len == 0)
- return;
-
- for (;;) { /* only a coding structure */
- len -= 2; /* skip 3270 cmd & WCC */
- ptr += 2;
- if (len < 6) break; /* 7171 sba's */
- if (*ptr != 0x11 || *(ptr+3) != 0x11) {
- cmd (ptr - 2, len + 2); /* see what host had to say */
- break;
- }
- len -= 6; /* skip 7171 headers */
- ptr += 6;
- if (len < 10) break; /* ft3270 stuff */
-
- for (emdp->rcv_pkt.len = 0, i = 0; i < 4; ++i)
- /* get packet length */
- emdp->rcv_pkt.len = (emdp->rcv_pkt.len << 4) + (*ptr++ & 0x0f);
- for (emdp->rcv_pkt.chk = 0, i = 0; i < 4; ++i)
- /* get packet chksum */
- emdp->rcv_pkt.chk = (emdp->rcv_pkt.chk << 4) + (*ptr++ & 0x0f);
-
- emdp->input_cnt = len - 9;
- /* len(4) + chksum(4) + 0x7f trailer */
- BlockMove(ptr, emdp->rcv_pkt.data, (long) emdp->input_cnt);
- if (ft_process()) /* unravel headers & call ft3270() */
- ft_req(); /* rc != 0: request re-xmission */
- return; /* do not cancel file transfer */
- }
- ft_done(); /* an error occurred */
- }
-
-
-
- /* process an ft3270 packet */
- /* if ok call ft3270 & return 0 otherwise rc != 0 */
-
- ft_process()
- {
- int i, length;
- unsigned chksum;
- unsigned char *buff, *buf1;
-
- if ((emdp->ft_flag & NEGO) && (!(emdp->ft_flag & C19) || (emdp->ft_flag & FTASCII)))
- emdp->ft_flag |= NOSTRIP;
- if (!(emdp->ft_flag & NEGO) || (emdp->ft_flag & FILERCV)) buff = emdp->ft3270_buff;
- else buff = &emdp->ack_buff[0];
- if (emdp->ft_flag & NOSTRIP) buf1 = buff;
- else buf1 = emdp->tbuff;
-
- if (emdp->rcv_pkt.len != emdp->input_cnt)
- return (1);
- *(emdp->rcv_pkt.data+emdp->input_cnt) = 0; /* pad with a zero for cksumming */
- chksum = ~cksum (emdp->rcv_pkt.data, (emdp->input_cnt + 1) >> 1);
- if (emdp->rcv_pkt.chk != (chksum))
- return (2);
- for (i = length = 0; i < emdp->input_cnt; i++, length++) {
- if (*(emdp->rcv_pkt.data+i) == ESC_CHAR)
- if (*(emdp->rcv_pkt.data+(++i)) != ESC_CHAR)
- *(emdp->rcv_pkt.data+i) = ft_input_table[*(emdp->rcv_pkt.data+i) & 0x0f];
- buf1[length] = *(emdp->rcv_pkt.data+i);
- }
- /* now we have 7 bit data */
-
- if (!(emdp->ft_flag & NOSTRIP))
- if ((length = bit_rest (emdp->tbuff, buff, length)) == 0)
- return (3);
- ft3270(buff, length - 2);
- return (0);
- }
-
- /* build an ft3270 packet out of some file transfer data */
-
- ft_upload(ptr, len)
- unsigned char *ptr;
- int len;
- {
- int i, j, k;
- unsigned chksum;
- unsigned char *buff;
-
- if (!(emdp->ft_flag & NOSTRIP)) {
- buff = emdp->tbuff; /* decide whether or not to */
- len = bit_strip (ptr, emdp->tbuff, len); /* make 7 bit data */
- }
- else /* avoid temp. buffer */
- buff = ptr;
-
- for (i = j = 0; i < len; i++, j++) { /* process special characters */
- if (buff[i] == ESC_CHAR) /* into escape sequences */
- *(emdp->send_pkt.data+j++) = ESC_CHAR; /* esc duplicates itself */
- else if ((k = ft_scan (ft_table, buff[i], NUMESC)) != -1) {
- *(emdp->send_pkt.data+j++) = ESC_CHAR; /* a hit */
- buff[i] = 0x40 + k; /* use table index */
- }
- *(emdp->send_pkt.data+j) = buff[i];
- }
-
- *(emdp->send_pkt.data+j) = 0; /* pad with a zero for cksumming */
- chksum = (~cksum (emdp->send_pkt.data, (j + 1) >> 1));
- for (i = 12, k = 0; i >= 0; i -= 4, k++) /* make length as 4 characters */
- emdp->send_pkt.lbuff[k] = ((j >> i) & 0x0f) | 0x40;
- for (i = 12, k = 0; i >= 0; i -= 4, k++) /* make chksum as 4 characters */
- emdp->send_pkt.cbuff[k] = ((chksum >> i) & 0x0f) | 0x40;
- emdp->send_pkt.pkt_len = j + 8; /* store real length of packet */
- ft_header();
- send_block(emdp->send_pkt.lbuff, 8);
- send_block(emdp->send_pkt.data, j);
- ft_trailer();
- }
-
- /*
- * Order of processing ft3270 data packets:
- * 1) see if we are being shut down by host program.
- * 2) quit abnormally if we are expecting host close & didn't get it.
- * 3) check for user halt.
- * 4) verify 1st byte of data stream.
- * 5) if we haven't already processed negotiation, then this is it.
- * 6) check for re-transmission request.
- * 7) deal with respective eof's.
- * 8) copy data.
- */
-
- ft3270(ptr, length)
- unsigned char *ptr;
- int length;
- {
- unsigned char ack;
- int i;
-
- if (*ptr == SHUTDOWN) { /* normal termination */
- ftack(RENTER);
- ft_done();
- return;
- }
- if (emdp->ft_flag & DONE) { /* abnormal termination */
- ftack(RPF10);
- ft_done();
- return;
- }
- if (emdp->ft_flag & HALT) { /* user requested halt */
- ftack(RPA1);
- return;
- }
- if (*ptr++ != FT3270) { /* verify 1st byte */
- ftack(RPF9);
- return;
- }
- if (!(emdp->ft_flag & NEGO)) { /* we need to process negotiation string */
- if (i = ftnego (ptr)) /* must be an error */
- ftack (i);
- #ifdef PC
- ft_banner();
- #else
- arcinit(emdp->ftname);
- byte_out (emdp->fttotal, 13);
- #endif
- if (i == 0) emdp->ft_flag |= NEGO;
- return;
- }
- if (*ptr == REXMIT) { /* re-transmit is called for */
- if (emdp->ft_flag & FILERCV) /* if download */
- ftack (emdp->ack_buff[0]); /* resend the last ack */
- else /* else resend the buffer */
- ft_upload (emdp->ft3270_buff, emdp->upload_cnt);
- byte_out (++emdp->re_xmit, 15);
- return;
- }
- if (emdp->ft_flag & FILERCV) { /* check for eof from host */
- if (*ptr == DOWNEOF)
- emdp->ft_flag |= FEOF;
- }
- else if (emdp->ft_flag & FEOF) { /* or see whether to send one */
- ftack(RPA2);
- fclose(emdp->ft1);
- return;
- }
-
- if (emdp->ft_flag & FILERCV) { /* download */
- ptr++; /* position at start of data */
- emdp->ftxfered += length;
- if (emdp->ft_flag & FTASCII) {
- while (length--) {
- if (*ptr == 0x0a) { /* end of "record" */
- /* if (ft_wrt(0xa)) return(); not on the mac--kevin*/
- if (ft_wrt(0x0d)) return();
- }
- else /* normal text */
- if (ft_wrt(*ptr)) return();
- ptr++;
- } /* end while loop */
- }
- else
- while (length--)
- if (ft_wrt(*ptr++)) return();
-
- ack = RENTER; /* default ack */
- if (emdp->ft_flag & FEOF) {
- if (emdp->ftcnt > 0) { /* write out any remaining data */
- if (fwrite (emdp->ftbuff, 1, emdp->ftcnt, emdp->ft1) != emdp->ftcnt)
- ack = RPF6; /* error */
- }
- fclose(emdp->ft1);
- if (ack == RENTER) {
- /* success: load the file into the edit window? */
- textdownedit(emdp->ftname);
- }
- emdp->ft_flag |= DONE;
- }
- ftack (ack); /* ack with RENTER or RC */
- }
- else { /* upload */
- emdp->ft3270_buff[0] = RENTER;
- for (emdp->upload_cnt = 1; emdp->upload_cnt <= emdp->ftlen; emdp->ftptr++, emdp->ftcnt--) {
- if (emdp->ftcnt == 0) {
- if ((emdp->ftcnt = fread (emdp->ftptr = emdp->ftbuff, 1, DOSLEN, emdp->ft1)) == 0) {
- emdp->ft_flag |= FEOF;
- break;
- }
- }
- if (emdp->ft_flag & FTASCII) {
- /* if (*emdp->ftptr == 0x1a || *emdp->ftptr == 0x0d); ignore CR & EOF NOT ON THE MAC--kevin*/
- if (*emdp->ftptr == 0x0d)
- emdp->ft3270_buff[emdp->upload_cnt++] = 0x0a; /* CR -> LF for upload on the Mac */
- else
- emdp->ft3270_buff[emdp->upload_cnt++] = *emdp->ftptr;
- /* TODO CR-LF??? */
- }
- else
- emdp->ft3270_buff[emdp->upload_cnt++] = *emdp->ftptr;
- } /* ....end of for loop */
- emdp->ftxfered += (emdp->upload_cnt - 1);
- ft_upload(emdp->ft3270_buff, emdp->upload_cnt);
- }
- byte_out (emdp->ftxfered, 14);
- } /* end of ft3170 subroutine */
-
-
- /* return index of passed character or -1 if not present */
-
- ft_scan(charp, thechar, len)
- register char * charp;
- register char thechar;
- register int len;
- {
- int thelen;
-
- thelen = len;
- for ( ; len > 0 && *charp++ != thechar ; --len)
- ;
- if (len)
- return(thelen - len);
- else
- return(-1);
- }
-
-
-
- /* repeatedly restore the high order bits from 8th byte to 7 previous bytes */
-
- bit_rest(from, to, len)
- register char * from;
- register char * to;
- int len;
- {
- register unsigned char highbits;
- register int count;
- register int newlen;
-
- newlen = 0;
- for ( ; len > 0; len -= 8, from++) {
- if (len < 8)
- count = len - 1;
- else
- count = 7;
- highbits = *(from + count);
- newlen += count;
- while (--count >= 0) {
- /* Note that the bits for final sequences < 8 wind up in different places */
- if (highbits & 0x01)
- *to++ = *from++ | 0x80;
- else
- *to++ = *from++;
- highbits >>= 1;
- }
- }
- return(newlen);
- }
-
- /* repeatedly take the high order bits from 7 consecutive bytes & store them in 8th byte */
-
-
- bit_strip(from, to, len)
- register char * from;
- register char * to;
- int len;
- {
- register unsigned char * highbits;
- register int count;
- register int newlen;
- register char frombyte;
-
- newlen = 0;
- for ( ; len > 0; len -= 7, to++) {
- /* outside loop: get the high bit marker for 1-7 bytes repeatedly */
- if (len < 7)
- count = len;
- else
- count = 7;
- highbits = to + count;
- *highbits = 0;
- newlen += count + 1;
- while (--count >= 0) {
- frombyte = *from++;
- if (frombyte & 0x80) {
- frombyte &= 0x7f;
- *highbits |= 0x80;
- }
- *to++ = frombyte;
- *highbits >>= 1;
- }
- if (len < 7)
- *highbits >>= 7 - len;
- }
- return(newlen);
- }
-
-
- /***************************************************************************
- **** 3270 File Transfer Negotiation & Utility Routines ****
- **** written by Peter Hoyt, Cornell Computer Services ****
- ***************************************************************************/
-
-
- /* initialize routine for file transfer:
- * ptr points to a 32 bit unsigned (high bytes first) length in bytes
- * beyond that is a one byte extra field
- * bit 0: replace filename if it already exists
- * bit 1: ascii/ebcdic conversion
- * bit 2: use default binary filename extensions
- * beyond that is the path spec terminated by a binary zero
- */
-
- ftnego(ptr)
- unsigned char *ptr;
- {
- unsigned char direction, *ftype;
- unsigned long length, avail;
- int i, j;
- union {
- unsigned long _l;
- unsigned char _c[4];
- } foo;
- char * ftnamep;
-
- direction = *ptr++;
- for (length = 0, i = 0; i < 4; i++)
- length = (length << 8) + (*ptr++);
- emdp->extra = *ptr;
- ftnamep = ++ptr; /* ptr now points to path spec */
-
- /* convert filespec to ascii and isolate filename extension */
- for (ftype = 0, emdp->fnamelen = 0; *ptr; emdp->fnamelen++, ptr++)
- if ((*ptr = *(ebctoasc + *ptr)) == '.') ftype = ptr + 1;
-
- #ifndef PC
- /* reinterpret the pathname for the macintosh */
-
- emdp->ftname = malloc((unsigned) strlen(ftnamep) + 1);
- macpath(ftnamep, emdp->ftname);
- mac_setdownvol(); /* fix the directory for multiple sessions */
-
- #endif
-
-
- emdp->ack_buff[0] = RENTER; /* if all goes well ack with RENTER */
-
- emdp->ft_flag |= (emdp->extra & CONV); /* CONV bit turns on FTASCII flag */
- if (emdp->extra & LOOKUP) { /* let pc determine defaults */
- emdp->ft_flag &= ~FTASCII; /* clear conversion bit */
-
- /* only the PC version has this code... */
- emdp->ft_flag |= FTASCII; /* no table match: do conversion */
- emdp->ack_buff[1] = emdp->ft_flag & FTASCII; /* return non zero if no match */
- }
-
- if (direction == DOWNLOAD) {
- emdp->ft_flag |= FILERCV;
- emdp->fttotal = length;
- if (emdp->extra & REP) /* replace file of same name */
- unlink(emdp->ftname);
- else if ( (emdp->ft1 = fopen (emdp->ftname, "r")) != NULL) {
- /* file already exists */
- fclose(emdp->ft1);
- return(RPF1);
- }
- if ((avail = free_sp (emdp->ftname)) == 0) /* see if room on disk */
- return (RPF2);
- if (avail < length) /* insufficient space */
- return (RPF3);
- if ((emdp->ft1 = fopen (emdp->ftname, "w")) == 0) /* open for real now */
- return (RPF4);
- ft_upload (&emdp->ack_buff[0], 2);
- return (0); /* successful negotiations */
- }
- else if (direction == UPLOAD) {
- textupedit(emdp->ftname); /* convert text if necessary */
-
- length = 0;
- if ((emdp->ft1 = fopen (emdp->ftname, "r")) == 0) /* open failure */
- return (RPF5);
- if (fseek (emdp->ft1, length, 2) == -1) /* position at eof */
- return (RPF7);
- emdp->fttotal = foo._l = ftell (emdp->ft1); /* get length in bytes */
- if (fseek (emdp->ft1, length, 0) == -1) /* reposition at tof */
- return (RPF8);
-
- for (i = 3; i >= 0; i--) /* copy length to buffer */
- emdp->ack_buff[i + 2] = foo._c[i]; /* PORT changed for mac, was emdp->ack_buff[5-i], kevin */
- ft_upload (&emdp->ack_buff[0], 6);
- emdp->send_pkt.data = emdp->xfer1_buff; /* switch the buffers */
- emdp->rcv_pkt.data = emdp->xfer2_buff;
- return (0); /* successful negotiations */
- }
- else /* error! */
- return (RPF9);
- }
-
-
- /* initial contact with host program */
-
- ftinit(hostvers, c19)
- int hostvers, c19;
- {
- if (c19) emdp->ftlen = C19FTLEN;
- else emdp->ftlen = TNFTLEN;
-
-
- if (makeftmem())
- return(ESC_CHAR); /* tell host to continue */
-
- emdp->rcv_pkt.data = emdp->xfer1_buff; /* buffers default */
- emdp->send_pkt.data = emdp->xfer2_buff;
-
- switch (hostvers) {
- case 20: /* acceptable version numbers */
- emdp->ftcnt = 0; /* index into DOS file buffer */
- emdp->ftxfered = emdp->re_xmit = 0;
- emdp->input_cnt = emdp->input_state = 0;
- emdp->ft_flag = 0;
- if (c19) emdp->ft_flag |= C19;
- return (PROGVERS); /* tell host to continue */
- break;
- default: /* tell host no dice */
- return (ESC_CHAR);
- }
- }
-
- /* send a packet of one byte acknowledgement */
-
- ftack(x)
- unsigned x;
- {
- emdp->ack_buff[0] = x;
- ft_upload (&emdp->ack_buff[0], 1);
- if (x != RENTER && x != REXMIT)
- emdp->ft_flag |= DONE;
- }
-
-
-
- /* the following are Mac-specific routines */
-
- /* draw a circle for a pie to show how much of a file has been transferred */
-
-
- arcinit(filename)
- unsigned char * filename;
- {
- GrafPtr oldport;
- int oldfont;
- int oldsize;
- Str255 filesize;
-
- GetPort(&oldport);
-
- emdp->arcdeg = 0;
- emdp->arcrect.top = 60;
- emdp->arcrect.left = 140;
- emdp->arcrect.bottom = 270;
- emdp->arcrect.right = 350;
-
- emdp->textrect.top = 20;
- emdp->textrect.left = 20;
- emdp->textrect.bottom = 80;
- emdp->textrect.right = 370;
-
- #ifdef FTWIND
- ctop(filename);
- arcwind = NewWindow((Ptr) NULL, &emdp->arcrect, filename, (Boolean) TRUE, 0, (WindowPtr) -1, (Boolean) FALSE, 0L);
- ptoc(filename);
- SetPort(arcwind);
-
- emdp->arcrect.top -= 10;
- emdp->arcrect.left -= 10;
- emdp->arcrect.bottom -= 10;
- emdp->arcrect.right -= 10;
- #else
- SetPort(emwindow);
- #endif
-
- selreset(emdp); /* reset selection rectangle */
-
- /* draw the file name */
- oldfont = thePort->txFont;
- oldsize = thePort->txSize;
- TextFont(0); /* System Font */
- TextSize(12);
-
- ClipRect(&emdp->textrect);
- MoveTo(emdp->textrect.left + 10, emdp->textrect.top + 20);
- DrawText(filename, 0, strlen(filename));
-
- MoveTo(emdp->textrect.left + 10, emdp->textrect.top + 35);
- NumToString(emdp->fttotal, &filesize);
- DrawString(&filesize);
- DrawString("\P bytes");
-
- MoveTo(emdp->textrect.left + 10, emdp->textrect.top + 50);
- DrawString("\PUse PA1 to abort");
-
- ClipRect(&emwindow->portRect);
- TextFont(oldfont);
- TextSize(oldsize);
-
- FrameOval(&emdp->arcrect);
-
- SetPort(oldport);
- }
-
-
- /* erase the circle */
-
- arcerase()
- {
- #ifdef FTWIND
- DisposeWindow(arcwind);
- #else
- EraseRect(&emdp->arcrect);
- EraseRect(&emdp->textrect);
- #endif
- }
-
-
- byte_out(cnt, line)
- long cnt;
- int line;
- {
- int newarc;
- float total;
- float count;
-
- if (line == 13)
- /* Peter's total count, ignore it */
- return(-1);
- if (cnt > emdp->fttotal)
- count = emdp->fttotal;
- else
- count = cnt;
- total = emdp->fttotal;
- newarc = (count / emdp->fttotal) * 360;
- /* percentage of arc completed */
- if (newarc > emdp->arcdeg) {
- GrafPtr oldport;
-
- GetPort(&oldport);
- #ifdef FTWIND
- SetPort(arcwind);
- #else
- SetPort(emwindow);
- #endif
- /* draw more of the wedge */
- #ifdef INVERT
- InvertArc(&emdp->arcrect, emdp->arcdeg, newarc - emdp->arcdeg);
- #else
- FillArc(&emdp->arcrect, emdp->arcdeg, newarc - emdp->arcdeg, &gray);
- #endif emdp->arcdeg = newarc;
- SetPort(oldport);
- }
- }
-
- arcrefresh()
- {
- if (! (emdp->event_reg & TFTP_ON))
- return(-1);
- EraseRect(&emdp->arcrect);
- arcinit(emdp->ftname);
-
- byte_out(emdp->ftxfered, 14);
- }
-
- /* restore Macintosh program to terminal emulation state */
-
- ft_done()
- {
- extern int mode;
-
- emdp->event_reg |= LINE_25;
- emdp->event_reg &= ~TFTP_ON;
- msetsendm(TRUE);
- mode = vtmode = 0;
- free(emdp->ftname);
- arcerase();
- }
-
- /* user requested break via PA1 */
-
- ft_usr() {
- if (!(emdp->ft_flag & HALT)) emdp->ft_flag |= HALT;
- else if (!(emdp->ft_flag & DONE)) emdp->ft_flag |= DONE;
- else ft_done();
- }
-
- /* request a re-xmission */
-
- ft_req() {
- ftack (RPA3);
- byte_out (++emdp->re_xmit, 15);
- }
-
-
- /* place character in DOS buffer and write when full */
-
- ft_wrt (c)
- char c;
- {
- emdp->ftbuff[emdp->ftcnt++] = c;
- if (emdp->ftcnt != DOSLEN) return(0);
- if (fwrite (emdp->ftbuff, 1, emdp->ftcnt, emdp->ft1) != emdp->ftcnt) {
- ftack(RPF6);
- return(1);
- }
- emdp->ftcnt = 0;
- return(0);
- }
-
-
- /* free memory used by transfer buffers */
-
- ftrecovermem(twp)
- struct winds * twp;
- {
- if (twp->xfer1_buff)
- free(twp->xfer1_buff);
- if (twp->xfer2_buff)
- free(twp->xfer2_buff);
- if (twp->tbuff)
- free(twp->tbuff);
- if (twp->ft3270_buff)
- free(twp->ft3270_buff);
- if (twp->ftbuff)
- free(twp->ftbuff);
-
- twp->xfer1_buff = NULL;
- twp->xfer2_buff = NULL;
- twp->tbuff = NULL;
- twp->ft3270_buff = NULL;
- twp->ftbuff = NULL;
- }
-
-
- /* allocate memory for a file transfer, return -1 if we can't */
-
- makeftmem()
- {
- if (emdp->xfer1_buff)
- return(0);
-
- if (memtest((long) (MAXLEN + TBUFLEN + TNFTLEN + DOSLEN + TNFTLEN), "to perform download")) {
- /* verify there's enough memory */
- emdp->xfer1_buff = malloc(MAXLEN);
- emdp->rcv_pkt.data = emdp->xfer1_buff; /* buffers default */
- emdp->xfer2_buff = malloc(20);
- emdp->send_pkt.data = emdp->xfer2_buff;
- emdp->tbuff = malloc(TBUFLEN);
- emdp->ft3270_buff = malloc(TNFTLEN+10);
- emdp->ftbuff = malloc(DOSLEN);
- }
- if ( emdp->xfer1_buff == NULL
- || emdp->xfer2_buff == NULL
- || emdp->tbuff == NULL
- || emdp->ft3270_buff == NULL
- || emdp->ftbuff == NULL
- ) {
- ftrecovermem(emdp);
- return(-1);
- }
- return(0);
- }
-
-
- /* ft3270 support */
-
-
- /* header for file transfer packets */
-
- ft_header()
- {
- if (emdp->ft_flag & C19) {
- /* no header */
- ;
- }
- else {
- /* 3270 currently always uses Telnet anyway... */
-
- (*emdp->putchar)(0xe8);
- (*emdp->putchar)(0x00);
- (*emdp->putchar)(0x00);
- }
- }
-
- /* trailer for file transfer packets */
-
- ft_trailer()
- {
- if (emdp->ft_flag & C19) {
- (*emdp->putchar)(CR);
- (*emdp->putflush)();
- }
- else {
- (*emdp->putchar)(0x0d);
- (*emdp->putchar)(TNIAC);
- (*emdp->putchar)(0xef);
- (*emdp->putflush)();
- }
- }
-
- /* send a block of data */
-
- send_block(ptr, len)
- unsigned char *ptr;
- int len;
- {
- if (emdp->conntype == CONN_SERD) {
- /* try to fix hanging problems with Sytek */
- sersendcount(ptr, len);
- }
- else {
- len++;
- while (--len)
- (*emdp->putchar)(*ptr++);
- }
- }
-
-